package cn.net.wanji.entity;

import cn.net.wanji.config.CommonParamConfig;
import cn.net.wanji.utils.DateUtils;
import cn.net.wanji.utils.StringUtils;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.io.File;
import java.util.List;

/**
 * @author guodejun
 * @createTime 2022/10/28 10:38
 * @description
 */
@Data
public class JsonRoot {

    private String recordId;

    private String recordType;

    @JsonProperty(value = "ERID")
    private String ERID;
    @JsonProperty(value = "vehiclePicInfos")
    private List<VehiclePicInfo> vehiclePicInfos;

    @JsonProperty(value = "RSUInfos")
    private List<RSUInfo> RSUInfos;

    private String unlawfulMold;
    private String detectTime;
    private String unlawfulCredible;

    public VehicleRsuInfo getVehicleRsuInfo(String fileNginx) {
        VehicleRsuInfo vehicleRsuInfo = new VehicleRsuInfo();
        vehicleRsuInfo.setDetectTime(StringUtils.timeRevise(detectTime));
        vehicleRsuInfo.setRecordId(recordId);
        vehicleRsuInfo.setRecordType(recordType);
        vehicleRsuInfo.setErId(ERID);
        vehicleRsuInfo.setUnlawfulMold(unlawfulMold);
        vehicleRsuInfo.setConfidenceDegree(unlawfulCredible);

        if (vehiclePicInfos != null && vehiclePicInfos.size() > 0) {
            VehiclePicInfo vehiclePicInfo = vehiclePicInfos.get(0);
            vehiclePicInfo.updateVehicleRsuInfo(vehicleRsuInfo);
        }

        if (RSUInfos != null && RSUInfos.size() > 0) {
            RSUInfo rsuInfo = RSUInfos.get(0);
            rsuInfo.updateVehicleRsuInfo(vehicleRsuInfo);
        }

        // 计算 车牌号 缩写
        String licenseCode = vehicleRsuInfo.getLicenseCode();
        if (!StringUtils.isEmpty(licenseCode)) {
            String licenseAbbre = licenseCode.substring(0, 1);
            vehicleRsuInfo.setLicenseAbbre(licenseAbbre);
        }

        // 计算图片存放地址
//        String time = recordId.substring(19, 27);
        String time = DateUtils.getStrFormatYyyyMmdd(StringUtils.timeRevise(detectTime));
        if (StringUtils.isEmpty(vehicleRsuInfo.getUnlawfulMold())) {
            //稽核正常

            vehicleRsuInfo.setHeadImage(fileNginx + CommonParamConfig.AUDIT_IS_NORMAL+ File.separator+time+File.separator+ recordId + "/" + "0.jpeg");
            vehicleRsuInfo.setTailImage(fileNginx +  CommonParamConfig.AUDIT_IS_NORMAL+ File.separator+time+File.separator+recordId + "/" + "1.jpeg");
            vehicleRsuInfo.setSideImage(fileNginx + CommonParamConfig.AUDIT_IS_NORMAL+ File.separator+time+File.separator+ recordId + "/" + "2.jpeg");
            vehicleRsuInfo.setLicenseImage(fileNginx + CommonParamConfig.AUDIT_IS_NORMAL+ File.separator+time+File.separator+ recordId + "/" + "3.jpeg");
            vehicleRsuInfo.setVideo(fileNginx + CommonParamConfig.AUDIT_IS_NORMAL+ File.separator+time+File.separator+ recordId + "/" + "4.mp4");
            vehicleRsuInfo.setCompositeImage(fileNginx + CommonParamConfig.AUDIT_IS_NORMAL+ File.separator+time+File.separator+ recordId + "/" + "5.jpeg");
        }else {
            vehicleRsuInfo.setHeadImage(fileNginx + CommonParamConfig.AUDIT_ANOMALIES+ File.separator+time+File.separator+ recordId + "/" + "0.jpeg");
            vehicleRsuInfo.setTailImage(fileNginx +  CommonParamConfig.AUDIT_ANOMALIES+ File.separator+time+File.separator+recordId + "/" + "1.jpeg");
            vehicleRsuInfo.setSideImage(fileNginx + CommonParamConfig.AUDIT_ANOMALIES+ File.separator+time+File.separator+ recordId + "/" + "2.jpeg");
            vehicleRsuInfo.setLicenseImage(fileNginx + CommonParamConfig.AUDIT_ANOMALIES+ File.separator+time+File.separator+ recordId + "/" + "3.jpeg");
            vehicleRsuInfo.setVideo(fileNginx + CommonParamConfig.AUDIT_ANOMALIES+ File.separator+time+File.separator+ recordId + "/" + "4.mp4");
            vehicleRsuInfo.setCompositeImage(fileNginx + CommonParamConfig.AUDIT_ANOMALIES+ File.separator+time+File.separator+ recordId + "/" + "5.jpeg");
        }


        return vehicleRsuInfo;
    }

}
